var app = getApp();
Page({
  data: {
    isWxapp: true,
    userInfo: {
      id: 0,
      avatar: '/assets/images/avatar.png',
      nickname: '游客',
    },
	orderMoney: "0.00",
	backMoney: "0.00",
	persons: 0
  },
  onLoad: function () {
    var that = this;
	that.login();
  },
  onShow: function () {
    var that = this;
    if (app.globalData.userInfo) {
      that.setData({ userInfo: app.globalData.userInfo, isWxapp: that.isWxapp() });
    }
  },
  login: function () {
    var that = this;
	wx.showLoading({
			title: "加载中..."
	});
	
    app.login(function () {
      that.setData({ userInfo: app.globalData.userInfo, isWxapp: that.isWxapp() });
	  that.getMemberInfo();
    });
	
  },
  isWxapp: function () {
    return app.globalData.userInfo ? app.globalData.userInfo.username.match(/^u\d+$/) : true;
  },
  
  getMemberInfo()
  {
	  let token = wx.getStorageSync('token') || '';
	  
	  console.log("请求" + token);
	  
	  var that = this;
	  app.request('/user/getMemberInfo', {
	  	token: token,
	  }, function(data, ret) {
	  	console.log(data);
	  	that.setData({
	  		orderMoney:data.orderMoney,
			backMoney:data.backMoney,
			persons:data.persons
	  	});
	  }, function(data, ret) {
	  	that.error(ret.msg);
	  });
  },
  
  
  onShareAppMessage()
  {
    const promise = new Promise(resolve => {
      setTimeout(() => {
        resolve({
          title: '分享推广'
        })
      }, 2000)
    })
    return {
      title: '分享推广',
      path: '/page/index/index?share_user_id=123',
    }
  }
})
